Ext.define('Lms.rms.HardwareChangeInfoDialog',{
	openWindow : function(config) {
		Ext.apply(this, config);
		this.isEditableMode = false; 
		var title = LocaleUtil.getMessage('rms.menu.changeHistory');
		if(typeof(config) != 'undefined'){
			title += LocaleUtil.getMessage('rms.label.detail');
			this.isEditableMode = true;
		}else{
			title = LocaleUtil.getMessage('reg');
		}
		this.dialog = Common.openDialog(title, 500, null, [{
			text : LocaleUtil.getMessage('save'),
			scope : this,
			handler : function(){
				if(!this.form.isValid()) return;
				Common.confirm(LocaleUtil.getMessage('confirm'),LocaleUtil.getMessage('rms.msg.doYouWantToSave'),function(btn){
					if(btn == 'yes'){
						var url;
						if(this.isEditableMode){
							//수정 logic
							url = 'hardwareChange/update.do';
						}else{
							//등록 logic
							url = 'hardwareChange/create.do';
						}
						this.form.submit({
							url : url,
							params : this.form.getForm().getValues(),
							waitMsg: LocaleUtil.getMessage('rms.msg.waitToSaving'),
							scope : this,
							success : this.reloadParent,
							failure : Common.failureMessageSubmit
						});
//						Common.formSubmit({
//							url : url,
//							params : this.form.getValues(),
//							reloadPanelId : 'HardwareChangePanel',
//							closeDialog : this.dialog
//						},this);
					}
				},this);
			}
		},{
			text : LocaleUtil.getMessage('close'),
			cls : 'blue_button',
			scope : this,
			handler : this.reloadParent
		}]);
		this.dialog.resizable = true;
//		this.dialog.iconCls = 'detail_search';
		this.dialog.add(this.getForm());
		this.dialog.show();
	},
	
	reloadParent : function(){
		this.dialog.close();
		Ext.getCmp('HardwareChangePanel').getStore().reload();
	},
	
	getData : function(){
		this.form.load({
			url : 'hardwareChange/findInfo.do',
			params : {
				id : this.id
			}
		});
	},
	
	getForm : function(){
		var systemStore = new Ext.data.JsonStore({
			autoLoad:false,						
			fields: ['id','name'],
			proxy : {
				type : 'ajax',
				url : 'pc/list.do',
				actionMethods : {
					read : 'POST'					
				}
			}
		});
		
		this.form = Ext.widget('form',{
		    frame : false,
		    border : false,
		    region : 'north',
		    bodyPadding: '5 5 0',
	        defaults: {anchor: '100%'},
	        defaultType: 'textfield',
	        fieldDefaults: {
	        	labelAlign : 'right',
                labelWidth: 120,
                msgTarget : 'side'
            },
	        items :[{
	        		xtype : 'hiddenfield',
	        		name : 'id'
	        	},{
					xtype : 'displayfield',
					itemId : 'pcName',
					fieldLabel: LocaleUtil.getMessage('rms.label.systemName'),
					name : 'pcName',
					hidden : true,
				},{
	        		itemId : 'zone',
	        		xtype : 'combobox',
	        		store : new Ext.data.JsonStore({
	        			autoLoad:true,
	        			fields: ['id','name'],
	        			proxy : {
	        				url : 'zone/list.do',
	        				type : 'ajax'
	        			}	        			
	        		}),
	        		name: 'zone',
	        		fieldLabel: LocaleUtil.getMessage('rms.label.zone'),
	        		valueField: 'id',
    	          	displayField:'name',
    	          	allowBlank : false,
    	          	listeners : {
    	          		scope : this,
    	          		change : function(combo, newValue, oldValue, eOpts){
    	          			systemStore.load({
    	          				params : {
    	          					searchCategory : 'ZONEID',
    	          					searchWordTxt : newValue
    	          				}
    	          			});
    	          		}
    	          	}
                },{
                	itemId : 'parentId',
                	xtype : 'combobox',
                    fieldLabel: LocaleUtil.getMessage('rms.label.systemName'),
                    store : systemStore,
                    name: 'parentId',
                    valueField: 'id',
    	          	displayField:'name',
                    allowBlank : false,
                    queryMode: 'local',
                    readOnly : false,
                    emptyText : LocaleUtil.getMessage('rms.msg.FirstSelectZone'),
                    style:{textTransform: 'uppercase'}
                },{
                	xtype : 'textarea',
                	fieldLabel: LocaleUtil.getMessage('rms.label.changeReason'),
                    name: 'reason',
                    grow      : true,
                    readOnly : false
                },{
                	fieldLabel: LocaleUtil.getMessage('rms.label.oldHwName'),
                	name: 'oldHwName',
                	readOnly : false
                },{
                	fieldLabel: LocaleUtil.getMessage('rms.label.newHwName'),
                	name: 'newHwName',
                	readOnly : false
                }
            ]      
		});
		if(this.isEditableMode){
			this.form.remove(this.form.queryById('zone'),true);
			this.form.queryById('parentId').hide();
			this.form.queryById('pcName').show();
			this.getData();
		}
		return this.form;
	}
});